home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / netscape / applet / ConsoleFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  5.3 KB  |  221 lines

  1. package netscape.applet;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.Frame;
  7. import java.awt.GridBagConstraints;
  8. import java.awt.GridBagLayout;
  9. import java.awt.Insets;
  10. import java.awt.TextArea;
  11. import java.awt.Window;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import netscape.debug.Debugger;
  15.  
  16. class ConsoleFrame extends Frame {
  17.    Console console;
  18.    TextArea text;
  19.    Button reset;
  20.    Button hide;
  21.  
  22.    ConsoleFrame(Console var1) {
  23.       this.console = var1;
  24.       ((Frame)this).setTitle("Java Console");
  25.       GridBagLayout var2 = new GridBagLayout();
  26.       ((Container)this).setLayout(var2);
  27.       this.text = new TextArea(20, 60);
  28.       this.text.setEditable(false);
  29.       GridBagConstraints var3 = new GridBagConstraints();
  30.       var3.fill = 1;
  31.       var3.weightx = (double)1.0F;
  32.       var3.weighty = (double)1.0F;
  33.       var3.gridwidth = 0;
  34.       var2.setConstraints(this.text, var3);
  35.       ((Container)this).add(this.text);
  36.       HorizontalRule var4 = new HorizontalRule();
  37.       GridBagConstraints var5 = new GridBagConstraints();
  38.       var5.fill = 2;
  39.       var5.weightx = (double)1.0F;
  40.       var5.insets = new Insets(1, 1, 0, 0);
  41.       var5.gridwidth = 0;
  42.       var2.setConstraints(var4, var5);
  43.       ((Container)this).add(var4);
  44.       this.reset = new Button("Clear");
  45.       GridBagConstraints var6 = new GridBagConstraints();
  46.       var6.insets = new Insets(4, 0, 2, 4);
  47.       var6.anchor = 13;
  48.       var2.setConstraints(this.reset, var6);
  49.       ((Container)this).add(this.reset);
  50.       this.hide = new Button("Close");
  51.       GridBagConstraints var7 = new GridBagConstraints();
  52.       var7.insets = new Insets(4, 0, 2, 4);
  53.       var7.anchor = 13;
  54.       var2.setConstraints(this.hide, var7);
  55.       ((Container)this).add(this.hide);
  56.       ((Window)this).pack();
  57.    }
  58.  
  59.    public boolean handleEvent(Event var1) {
  60.       if (var1.id != 201 && (var1.target != this.hide || var1.id != 1001)) {
  61.          if (var1.target == this.reset && var1.id == 1001) {
  62.             this.console.reset();
  63.             return true;
  64.          } else {
  65.             return super.handleEvent(var1);
  66.          }
  67.       } else {
  68.          this.console.hide();
  69.          return true;
  70.       }
  71.    }
  72.  
  73.    String getFileFullPath(String var1) {
  74.       try {
  75.          File var2 = new File(".", var1);
  76.          SecurityManager.enablePrivilege("UniversalFileRead");
  77.          SecurityManager.enablePrivilege("UniversalPropertyRead");
  78.          return var2.getCanonicalPath();
  79.       } catch (IOException var3) {
  80.          return var1;
  81.       }
  82.    }
  83.  
  84.    public boolean keyDown(Event var1, int var2) {
  85.       if (var2 >= 48 && var2 <= 57) {
  86.          MozillaAppletContext.debug = var2 - 48;
  87.          System.err.println("# Applet debug level set to " + MozillaAppletContext.debug);
  88.          return true;
  89.       } else if (var2 != 98 && var2 != 66) {
  90.          if (var2 != 100 && var2 != 68) {
  91.             if (var2 != 119 && var2 != 87) {
  92.                if (var2 != 103 && var2 != 71) {
  93.                   if (var2 != 102 && var2 != 70) {
  94.                      if (var2 != 109 && var2 != 77) {
  95.                         if (var2 == 120) {
  96.                            String var7 = this.getFileFullPath("memory.out");
  97.                            System.err.print("# Dumping memory to '" + var7 + "'...");
  98.                            Console.dumpMemory(false);
  99.                            System.err.println("done.");
  100.                            return true;
  101.                         } else if (var2 == 88) {
  102.                            String var6 = this.getFileFullPath("memory.out");
  103.                            System.err.print("# Dumping memory to '" + var6 + "'...");
  104.                            Console.dumpMemory(true);
  105.                            System.err.println("done.");
  106.                            return true;
  107.                         } else if (var2 != 115 && var2 != 83) {
  108.                            if (var2 != 116 && var2 != 84) {
  109.                               if (var2 != 107 && var2 != 75) {
  110.                                  if (var2 != 99 && var2 != 67) {
  111.                                     if (var2 != 113 && var2 != 81) {
  112.                                        if (var2 != 104 && var2 != 72 && var2 != 63 && var2 != 32) {
  113.                                           if (var2 != 119 && var2 != 87) {
  114.                                              if (var2 != 108 && var2 != 76) {
  115.                                                 return super.keyDown(var1, var2);
  116.                                              } else {
  117.                                                 boolean var5 = !AppletClassLoader.getCaptureClassFiles();
  118.                                                 AppletClassLoader.setCaptureClassFiles(var5);
  119.                                                 System.err.println("# Class file capture " + (var5 ? "enabled" : "disabled"));
  120.                                                 return true;
  121.                                              }
  122.                                           } else {
  123.                                              System.err.print("# Dumping application heaps...");
  124.                                              Console.dumpApplicationHeaps();
  125.                                              System.err.println("done.");
  126.                                              return true;
  127.                                           }
  128.                                        } else {
  129.                                           this.printConsoleHelp();
  130.                                           return true;
  131.                                        }
  132.                                     } else {
  133.                                        this.console.hide();
  134.                                        return true;
  135.                                     }
  136.                                  } else {
  137.                                     this.reset();
  138.                                     return true;
  139.                                  }
  140.                               } else {
  141.                                  System.err.print("# Checkpointing memory...");
  142.                                  Console.checkpointMemory();
  143.                                  System.err.println("done.");
  144.                                  return true;
  145.                               }
  146.                            } else {
  147.                               String var4 = this.getFileFullPath("memory.out");
  148.                               System.err.print("# Dumping thread info to '" + var4 + "'...");
  149.                               Console.dumpNSPRInfo();
  150.                               System.err.println("done.");
  151.                               return true;
  152.                            }
  153.                         } else {
  154.                            String var3 = this.getFileFullPath("memory.out");
  155.                            System.err.print("# Dumping memory summary to '" + var3 + "'...");
  156.                            Console.dumpMemorySummary();
  157.                            System.err.println("done.");
  158.                            return true;
  159.                         }
  160.                      } else {
  161.                         this.printMemoryStats("Memory");
  162.                         return true;
  163.                      }
  164.                   } else {
  165.                      System.err.println("# Performing finalization...");
  166.                      System.runFinalization();
  167.                      this.printMemoryStats("Finalization complete: memory");
  168.                      return true;
  169.                   }
  170.                } else {
  171.                   System.err.println("# Performing a garbage collection...");
  172.                   System.gc();
  173.                   this.printMemoryStats("GC complete: memory");
  174.                   return true;
  175.                }
  176.             } else {
  177.                System.err.print("# Dumping application heaps...");
  178.                Console.dumpApplicationHeaps();
  179.                System.err.println("done.");
  180.                return true;
  181.             }
  182.          } else {
  183.             MozillaAppletContext.dumpState(System.err);
  184.             return true;
  185.          }
  186.       } else {
  187.          System.err.println("# Breaking into debugger.");
  188.          Debugger.debugBreak();
  189.          return true;
  190.       }
  191.    }
  192.  
  193.    void printMemoryStats(String var1) {
  194.       Runtime var2 = Runtime.getRuntime();
  195.       System.err.println("# " + var1 + ": " + var2.totalMemory() + " free: " + var2.freeMemory() + " (" + var2.freeMemory() * 100L / var2.totalMemory() + "%)");
  196.    }
  197.  
  198.    void printConsoleHelp() {
  199.       System.out.println("Netscape Java Console Commands:");
  200.       System.out.println("  b:   break into the debugger (Windows only)");
  201.       System.out.println("  c:   clear console window");
  202.       System.out.println("  d:   dump applet context state to console");
  203.       System.out.println("  f:   finalize objects on finalization queue");
  204.       System.out.println("  g:   garbage collect");
  205.       System.out.println("  h:   print this help message");
  206.       System.out.println("  l:   capture all classes loaded by an applet to a directory");
  207.       System.out.println("  m:   print current memory use to console");
  208.       System.out.println("  q:   hide console");
  209.       System.out.println("  s:   dump memory summary to \"memory.out\"");
  210.       System.out.println("  t:   dump thread info to \"memory.out\"");
  211.       System.out.println("  x:   dump memory to \"memory.out\"");
  212.       System.out.println("  X:   dump memory (detailed) to \"memory.out\"");
  213.       System.out.println("  0-9: set applet debug level to <n>");
  214.       System.out.println();
  215.    }
  216.  
  217.    void reset() {
  218.       this.text.setText("");
  219.    }
  220. }
  221.